<template>
  <transition name="fade">
    <div style="margin-top: 92px;">

      <div class="swiper_wrap">
        <div class="img_wrap" v-if="slider_data.length">
          <slider :isdos="true" :autoplay="true" :scroll_type="'slide'">
            <div v-for="(item, index) in slider_data" class="swiper-slide">
              <img v-lazy="item.pic_url" alt="" @click="toClass" :data-cid="class1[index].cid">
            </div>
          </slider>
        </div>
      </div>
      <div class="small_img_wrap">
        <ul>
          <li><img src="../assets/img/a1.jpg" alt=""></li>
          <li><img src="../assets/img/a2.jpg" alt=""></li>
          <li><img src="../assets/img/a3.jpg" alt=""></li>
        </ul>
      </div>
      <div class="all_class_wrap" v-if="class_data.length">
        <div v-for="(item , index) in class_data">
          <p class="class_title" :data-biao="class1[index].biaozhi"><span :style="{color:class1[index].color}">{{index+1}}F </span>{{class1[index].title}}
          </p>
          <class-item @selectItem="selectItem" :data="item.class"></class-item>
        </div>
      </div>
    </div>
  </transition>
</template>

<script type="text/ecmascript-6">
  import slider from 'base/slider'
  import classItem from 'components/ClassItem'
  import {getOffsetTop} from 'assets/dom/dom'
  import * as recommend from 'api/recommend'

  export default {
    props: ['iscancle'],
    data() {
      return {
        slider_data: [],
        class_data: [],
        class1: [
          {
            title: '电工辅料',
            biaozhi: 'ddy1',
            color: '#fcde00',
            cid: 5
          }, {
            title: '油工辅料',
            biaozhi: 'ddy2',
            color: '#00deff',
            cid: 72
          }, {
            title: '水工辅料',
            biaozhi: 'ddy3',
            color: '#ff00b4',
            cid: 60
          }, {
            title: '木工辅料',
            biaozhi: 'ddy4',
            color: '#36ff01',
            cid: 74
          }, {
            title: '瓦工辅料',
            biaozhi: 'ddy5',
            color: '#b3b3b1',
            cid: 28
          }, {
            title: '电工工具',
            biaozhi: 'ddy6',
            color: '#7f3d03'
          }
        ]
      }
    },
    mounted() {},
    created() {
      recommend.get_slider_list({}).then((res) => {
        if (res.status === 200) {
          let _res = res.data
          if (_res.resStatus === 0) {
            this.slider_data = _res.data
          }
        }
      }, (res) => {
      })

      recommend.get_class_list({}).then((res) => {
        if (res.status === 200) {
          let _res = res.data
          if (_res.resStatus === 0) {
            console.log(_res.data)
            this.class_data = _res.data;
          }
        }
      })
    },
    computed: {},
    methods: {
      toClass(e) {
        const cid = e.target.getAttribute("data-cid")
        this.$emit("setkeep", "allClass")
        this.$router.push({
          path: "/allClass",
          query: {
            class1: "",
            class2: cid,
            class3: "",
          }
        })
      },
      selectItem(id) {
        this.$emit('setkeep', "detial")
        this.$router.push({
          path: "/detial",
          query: {
            itemId: id
          }
        })
      }
    },
    components: {
      slider,
      classItem
    }
  }
</script>

<style scoped lang="scss">
  .swiper_wrap {
    width: 100%;
    padding-top: 41.5%;
    position: relative;
  }

  .img_wrap {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
  }

  .small_img_wrap {
    > ul {
      width: 100%;
      overflow: hidden;
      > li {
        float: left;
        width: 31.3%;
        margin: 1%;
        > img {
          width: 100%;
        }
      }
    }
  }

  .class_title {
    margin-top: 18px;
    text-align: left;
    padding-left: 12px;
    > span {
      font-size: 27px;
      font-weight: bold;
    }
  }

  .fade-enter-active /* .fade-leave-active below version 2.1.8 */
  {
    opacity: 0;
    transform: translateX(100%);
  }

  .fade-enter-to /* .fade-leave-active below version 2.1.8 */
  {
    opacity: 1;
    transform: translateX(0);
    transition: all .3s;
  }
</style>
